package com.yunhe.authority.repository.paymentInfo;

import com.yunhe.authority.domain.company.ContractAccessories;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName: ContractAccessoriesRepository
 * @Description:
 * @author: GongDaCheng
 * @Date: 14:53 2021/7/16
 */
@Repository
public interface ContractAccessoriesRepository extends Neo4jRepository<ContractAccessories, Long> {

    /**
     * @Description 合同与企业绑定
     * @Param Long companyId, Long id
     * @Return
     * @Date 2021/7/16 15:01
     */
    @Query("match (c:Company),(ca:ContractAccessories) where ID(c)={companyId} and ID(ca)={id} create (c)-[r:HAS_CONTRACT]->(ca)")
    void bindCompany(@Param("companyId") Long companyId, @Param("id") Long id);

    /**
     * @Description 合同与企业解绑并删除合同
     * @Param Long companyId, Long id
     * @Return
     * @Date 2021/7/19 9:31
     */
    @Query("match (c:Company)-[r:HAS_CONTRACT]->(ca:ContractAccessories) where ID(ca)={id} delete ca,r")
    void unbindAndDelete(@Param("id") Long id);

    /**
     * @Description 查看合同列表
     * @Param Long companyId
     * @Return List<ContractAccessories>
     * @Date 2021/7/19 9:55
     */
    @Query("match (c:Company)-[r:HAS_CONTRACT]->(ca:ContractAccessories) where ID(c)={companyId} return ca")
    List<ContractAccessories> findAll(@Param("companyId") Long companyId);
}
